package umage.action;

import java.awt.event.ActionEvent;

import org.jhotdraw.app.Project;
import org.jhotdraw.draw.Drawing;
import org.jhotdraw.draw.Figure;

import umage.figures.PlaceFigure;
import umage.figures.TransitionFigure;
import umage.projects.UMageProject;

@ActionInfo(name = "Reset Petri Net", menu = "Petri Net")
public class ResetPetriNetAction extends DefaultAction {

	@Override
	public void actionPerformed(ActionEvent e) {
		Project p = getApplication().getCurrentProject();
		if (p == null || !(p instanceof UMageProject)) return;
		Drawing d = ((UMageProject)p).getDrawingEditor().getView().getDrawing();
		
		for (Figure figure : d.getFigures()) {
			if (figure instanceof PlaceFigure) ((PlaceFigure)figure).reset();
			else if (figure instanceof TransitionFigure) ((TransitionFigure)figure).clearFire();
		}
	}

}
